//
//  AFN.m
//  
//
//  Created by Jessica on 15/10/28.
//
//

#import "AFN.h"
#import "AFNetworking.h"
@implementation AFN
+ (void)getdataWithString:(NSString *)string block:(AFNData)block
{
    
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url_string = [NSString stringWithFormat:@"%@",string];
    
    AFHTTPSessionManager* manager = [AFHTTPSessionManager manager];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"text/json", @"application/json", @"text/javascript", @"text/html",  nil];
    [manager GET:url_string parameters:nil success:^(NSURLSessionTask *task, id responseObject) {
        [netWorkManager stopMonitoring];
        block(responseObject);
//        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        //BLOCK (operation);
    }];
}



+ (void)postdataWithString:(NSString *)string bodyStr:(NSDictionary *)bodyStr block:(AFNData)block
{
    
    AFHTTPSessionManager* manager = [AFHTTPSessionManager manager];
    
    
    //    申明返回的结果是json类型
    //    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    //申明请求的数据是json类型
//    manager.requestSerializer=[AFJSONRequestSerializer serializer];
    
    //如果报接受类型不一致请替换一致text/html或别的
    
    //    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"text/json", @"application/json", @"text/javascript", @"text/html",  nil];
    
    [manager POST:string parameters:bodyStr success:^(NSURLSessionDataTask *task, id responseObject) {
        
//        NSLog(@"%@", responseObject);
        block(responseObject);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"Error: %@", error);
        
    }];
}




@end
